// pages/media/video.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    videoWidth: 0,
    videoHeight: 0,
    currentIndex: 0,
    videoControl:{
      index:0,
      videoList:[],
      playSrc:''
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initVideo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //初始化视频播放器
  initVideo: function () {
    var that = this;
    var width = wx.getSystemInfoSync().windowWidth;
    var height = width * 9 / 16;
    this.setData({
      videoWidth: width,
      videoHeight: height
    });

    var videoList = JSON.parse(wx.getStorageSync("videoList"));
    console.log("videoList", videoList);
    var index = that.data.videoControl.index;
    that.setData({
      "videoControl.videoList":videoList,
      "videoControl.playSrc" : videoList[index].url
    })

    console.log("videoControl",that.data.videoControl);
  },
  //选择视频播放
  chooseVideo:function(e){
    var index = parseInt(e.currentTarget.dataset.index);
    var that = this;
    var videoList = that.data.videoControl.videoList;
    that.setData({
      "videoControl.index":index,
      "videoControl.playSrc":videoList[index].url
     })
  }
})